package Doudizhu;

import ScissorsGame.Player;

import java.util.*;

/**
 * 斗地主
 */
public class Doudizhu {

    private List<Card> poker = new ArrayList(); //牌
    private List<Card> palyer1 = new ArrayList();
    private List<Card> palyer2 = new ArrayList();
    private List<Card> palyer3 = new ArrayList();
    private List<Card> hand = new ArrayList();

    public List<Card> getPalyer1() {
        return palyer1;
    }

    public void setPalyer1(List<Card> palyer1) {
        this.palyer1 = palyer1;
    }

    public List<Card> getPalyer2() {
        return palyer2;
    }

    public void setPalyer2(List<Card> palyer2) {
        this.palyer2 = palyer2;
    }

    public List<Card> getPalyer3() {
        return palyer3;
    }

    public void setPalyer3(List<Card> palyer3) {
        this.palyer3 = palyer3;
    }

    public List<Card> getHand() {
        return hand;
    }

    public void setHand(List<Card> hand) {
        this.hand = hand;
    }

    public void init() {  //扑克初始化
        String[] points = {"3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15"};
        String[] typs = "1,2,3,4".split(",");
        for (int i = 0; i < points.length; i++) {  //遍历，分别给52张牌附上不同的花色
            for (int j = 0; j < typs.length; j++) {
                poker.add(new Card(points[i] + "_", typs[j], i, j));
//                System.out.println(poker);
            }

        }
        poker.add(new Card("16_1", "", 14, 0));  //大王序号14
        poker.add(new Card("17_1", "", 13, 0));  //小王序号13


    }

    public void xipai() {  //洗牌
        Collections.shuffle(poker);  //打乱顺序

    }

    public void faPai() { //发牌
        palyer1 = poker.subList(0, 17); //玩家1发牌
        palyer2 = poker.subList(17, 34); //玩家2发牌
        palyer3 = poker.subList(34, 51); //玩家3发牌
        hand = poker.subList(51, 54);  //底牌三张
        sort(palyer1);
        sort(palyer2);
        sort(palyer3);
        sort(hand);
//        System.out.println("玩家1" + palyer1);
//        System.out.println("玩家2" + palyer2);
//        System.out.println("玩家3" + palyer3);
//        System.out.println("底牌" + hand);


    }

    public void sort(List list) {  //扑克排序
        list.sort(new Comparator<Card>() {
            @Override
            public int compare(Card o1, Card o2) {
                if (o1.getNumber() == o2.getNumber()) {  //判断，如果牌数字相同
                    return o1.getTypenum() - o2.getTypenum();  //用花色序号相减，结果正数交换（按照花色排序）
                } else {
                    return o1.getNumber() - o2.getNumber();   //如果不相同，用数字相减，结果正数交换
                }
            }
        });
    }


    //    public static void main(String[] args) {
//    Doudizhu doudizhu = new Doudizhu();
//        doudizhu.init();
//        doudizhu.xipai();
//        doudizhu.faPai();


}


